// request.cpp
// ~~~~~~~~~
//

#include "request.hpp"
#include <string>
#include <boost/lexical_cast.hpp>
#include "connection.hpp"
#include <iostream>


namespace http {
    namespace server3 {


        bool request::get_header_value(const std::string header_str, std::string& header_value_str)
        {
            std::vector<header>::iterator it;
            for ( it = headers.begin(); it < headers.end(); it++ )
            {
                if(it->name.compare(header_str) == 0 )
                {
                    header_value_str = it->value;
                    return true;
                }
            }
            return false;

        }
        void request::initialize_business_id()
        {
            const char *uri = this->uri.c_str();
            uri++; // ignore uri[0]='/'
            const char *ptr = uri;
            while(*ptr!='?'&&*ptr) ptr++;
            this->business_str = std::string(uri,ptr-uri);
        	return;
        }


        void request::add_header(const std::string &name_, const std::string &value_)
		{
			header header_;
			header_.name = name_;
			header_.value = value_;
			headers.push_back(header_);
		}
		void request::reset()
		{
			connection_id = 0;
            method.clear();
            uri.clear();
			http_version_major=0;
			http_version_minor=0;
            headers.clear();
        }        

    } // namespace server3
} // namespace http	
